package com.jzm.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtils {
    private static Connection connection;

    static {
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 获取数据库连接
     * @return
     * @throws SQLException
     */
    public static Connection getConnection() {
        try {
            return DriverManager.getConnection("jdbc:mysql://localhost:3306/fun_sports","root","root");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 关闭继承closeables相关的对象
     * @param closeables
     */
    public static void close(AutoCloseable... closeables){
        if(closeables != null && closeables.length > 0){

            for (AutoCloseable closeable : closeables) {
                if(closeable != null){
                    try {
                        closeable.close();
                    } catch (Exception e) {
                       e.printStackTrace();
                    }
                }

            }

        }
    }
}
